/*
 * @Author: windys
 * @Description: 
 * @Date: 2022-02-15 09:03:10
 */

import JSEncrypt from "jsencrypt";
// 加密
export function encruption(str) {
    let encrypt = new JSEncrypt();
    encrypt.setPublicKey(
        "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCfxYtZzD3Fjno9K/Xb97gIc6vO+ck/F0geBnZFuYPUohrRPFV80D0t119e/fSBb+fEA3ehom3qmAabU6dXdIRhLlTRuxvGUj9FVldx/N8G8ZoO+WrVFOGwGGp/j1/KJ0SaruSStNNkW9PKCzf3yuoD6ddzxQn17/Dor1NUVvGj9QIDAQAB"
    );
    return encrypt.encrypt(str);
}

// 检测是否是手机
export function is_moblie() {
    return (
        navigator.userAgent
            .toLowerCase()
            .match(
                /(ipod|ipad|iphone|android|coolpad|mmp|smartphone|midp|wap|xoom|symbian|j2me|blackberry|wince)/i
            ) != null
    );
}

// 是否在微信
export function is_weixin() {
    var ua = navigator.userAgent.toLowerCase();
    if (ua.match(/MicroMessenger/i) == "micromessenger") {
        return true;
    } else {
        return false;
    }
}

export function formatDateTime(inputTime) {
    var date = new Date(inputTime);
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? "0" + m : m;
    var d = date.getDate();
    d = d < 10 ? "0" + d : d;
    var h = date.getHours();
    h = h < 10 ? "0" + h : h;
    var minute = date.getMinutes();
    var second = date.getSeconds();
    minute = minute < 10 ? "0" + minute : minute;
    second = second < 10 ? "0" + second : second;
    return y + "-" + m + "-" + d + " " + h + ":" + minute + ":" + second;
}

// 时间格式化

export function fmtTime(time) {
    let yy = new Date(time).getFullYear();
    let mm = new Date(time).getMonth() + 1;
    let dd = new Date(time).getDate();
    let hh = new Date(time).getHours();
    let mf = new Date(time).getMinutes();
    let ss = new Date(time).getSeconds();
    if (hh < 10) {
        hh = '0' + hh
    }
    if (mf < 10) {
        mf = '0' + mf
    }
    if (ss < 10) {
        ss = '0' + ss
    }
    return `${yy}-${mm}-${dd} ${hh}:${mf}:${ss}`
}